<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <script src="js/mui.min.js"></script>
    <link href="css/mui.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="css/iconfont.css" />
    <link rel="stylesheet" href="css/style.css" />	
    <script src="js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="js/my.js" ></script>
</head>
<body>
	<header class="mui-bar mui-bar-nav">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title">更改密码</h1>
	</header>
	<div class="mui-content">
	    <div class="add-address-div">
	    	<form class="mui-input-group public-lable-txt">
	    		<!--<span id="msg" style="margin-left:100px;font-size:15px;color: red; display:none;">两次密码不一致！！！</span>-->
	    	   <div class="mui-input-row" style="margin-top: 15px;">
	    	        <label>用户名：</label>
	    	        <input type="text" id="username" name="username" />
	    	    </div>
	    		<div class="mui-input-row" >
	    	        <label>新密码：</label>
	    	        <input type="password" id="psw" name="password" class="mui-input-clear" placeholder="请输入新密码"/>
	    	    </div>
	    	    <div class="mui-input-row">
	    	        <label>重复密码：</label>
	    	        <input type="password" id="psw1"  class="mui-input-clear" placeholder="请重复密码"/>
	    	    </div>
	    	</form>
	    	<button class="public-g-btn" onclick="updatepsw()">确定</button>
	    </div>
	</div>
	<script src="js/castapp.js"></script>
	<script>
		mui.init();
		var userInfo = JSON.parse(localStorage.getItem("userInfo"));
		var url = localStorage.getItem("url");
		var realUrl=url+"/user/getUser"
			mui.ajax(realUrl, {
				data: {
						id: userInfo,
					},

						//服务器返回json格式数据 
						type: 'post', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；
						success: function(data) {
							if(data.code==0){
								
			                    $("#username").val(data.data.username);
			                    
							}

							
						},
						error: function(xhr, type, errorThrown) { //异常处理；
							console.log(type);
						}
					});
		
		function updatepsw(){
				var one = $("#psw").val();
				var two = $("#psw1").val();
				if (one =='') {
					mui.alert("密码不能为空！！！", "提示", "ok", function() {}, 'div');
					return;
				} else{
					if (one != two) {
					mui.alert("密码不一致！！！", "提示", "ok", function() {}, 'div');
					return;
				} else {
				var realUrl1=url+"/user/updatepsw"
				mui.ajax(realUrl1, {
					data: {
						username:$("#username").val(),
						psw:$("#psw").val()
					},
					dataType: 'json', //服务器返回json格式数据
					type: 'post', //HTTP请求类型
					timeout: 10000, //超时时间设置为10秒；
					success: function(data) {
						if(data.code == 0) {
							localStorage.clear();
							alert("修改成功，请重新登录");
							/*window.location.href="login.html";*/
							my.jump("login.html","login");

						}else{
							mui.toast(data.msg);
						}

					},
					error: function(xhr, type, errorThrown) { //异常处理；
						console.log(type);
					}
				});
				}
					
				}
				
		}
		
		
		
	</script>
</body>
</html>